package com.example.demo.common.config;

import com.example.demo.common.filter.MyFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 拦截器配置
 */
@Configuration
public class FilterConfig {

    @Bean
    public FilterRegistrationBean<MyFilter> myFilterRegistrationBean() {
        FilterRegistrationBean<MyFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new MyFilter());//注册拦截器
        registrationBean.addUrlPatterns("/*");//拦截地址
        registrationBean.setOrder(1);//拦截器优先级，数字越小优先级越高
        return registrationBean;
    }
}
